//
//  DongtaiShowView.m
//  UI_Homework_09
//
//  Created by 黄威 on 16/5/14.
//  Copyright © 2016年 黄威. All rights reserved.
//

#import "DongtaiShowView.h"
#import "DongtaiView.h"
@interface DongtaiShowView ()<UIScrollViewDelegate>
@property (nonatomic ,retain)UIScrollView *scroll;
@property (nonatomic ,retain)UIPageControl *page;

@end

@implementation DongtaiShowView

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createpage];
    [self createScrollView];
    self.automaticallyAdjustsScrollViewInsets = NO;
}





- (void)createScrollView{


    self.scroll = [[UIScrollView alloc]init];
    self.scroll.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    self.scroll.showsHorizontalScrollIndicator = NO;
    self.scroll.pagingEnabled = YES;
    self.scroll.bounces = NO;
    self.scroll.contentSize = CGSizeMake(CGRectGetWidth(self.view.bounds) * 10, CGRectGetHeight(self.view.bounds));

    self.scroll.delegate = self;


    for (NSInteger i = 0; i < 10; i++) {
        UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.view.bounds) * i, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))];
        
        NSString *str = [NSString stringWithFormat:@"%ld.jpg",i+1];
        imageview.image = [UIImage imageNamed:str];
        [self.scroll addSubview:imageview];
        
    }

    
    [self.view addSubview: self.scroll];

    [self.scroll setContentOffset:CGPointMake( CGRectGetWidth(self.view.bounds)* (self.number - 1), 0) animated:YES];
    
 
}

 
- (void)createpage{

    self.page = [[UIPageControl alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2 - 50, 600, 100, 40)];
    self.page.numberOfPages = 10;
    [self.view addSubview:self.page];
    CGPoint CGP = CGPointMake(375 * (self.number - 1), 0);
    self.page.currentPage = CGP.x / CGRectGetWidth(self.scroll.bounds);


}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    
    self.page.currentPage = scrollView.contentOffset.x / CGRectGetWidth(self.scroll.bounds);
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
